version 14.1
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE I OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

/* DEFINING TIME VARIABLE */		

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==0
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc location_code
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011
bys				regnor:g nreturns=_N
keep			if nreturns==6
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* GENERATING TREATMENT DUMMIES */

g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011

/* COLUMN (1) */

local			i=1
local			j=1
qui				reg logchange i.year tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (2) -- LINEAR */

local			i=1
local			j=`j'+1
qui				reg logchange trend tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (3) -- INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.industry2 tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (4) -- INDUSTRY-FE */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.industry2 tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (5) -- REGION-FE */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & location_code>0
matrix			table[`i',`j']=r(mean)

/* COLUMN (6) -- REGUION-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & location_code>0
matrix			table[`i',`j']=r(mean)

/* COLUMN (7) -- REGUION-SPECIFIC & INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code i.year*i.industry2 tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=. & location_code>0
matrix			table[`i',`j']=r(mean)

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table8-table9
keep			if _n<=8
g				c11=""
replace			c11="$\mbox{\emph{to-zero}} \times 2009$" in 1
replace			c11="$\mbox{\emph{to-zero}} \times 2010$" in 3
replace			c11="$\mbox{\emph{not-to-zero}} \times 2009$" in 5
replace			c11="Observations" in 7
forvalues 		c=1/7 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)6 {
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/7 {
replace			c`c'=string(table`c',"%15.0fc") in 7
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
replace			l="\\\\" in 6
browse			c11 s8 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l
